<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket Client</title>
</head>
<body>

<script>
    // 创建一个WebSocket连接
    const ws = new WebSocket('ws://localhost:8080');

    // 当连接打开时
    ws.onopen = function(event) {
        console.log('Connected to server');
        // 发送一个消息给服务器
        ws.send('Hello from client!');
    };

    // 当接收到来自服务器的消息时
    ws.onmessage = function(event) {
        console.log('Received:', event.data);
    };

    // 当连接关闭时
    ws.onclose = function(event) {
        console.log('Disconnected from server');
    };

    // 当发生错误时
    ws.onerror = function(error) {
        console.error('WebSocket Error:', error);
    };
</script>

</body>
</html>
